import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

class Demo3_1_4_1 {
    @SuppressWarnings("Convert2MethodRef")
    public static void main(String[] args) {
        List<Person> list = new ArrayList<>();
        list.add(new Person("张三", 10));
        list.add(new Person("李四", 11));
        list.add(new Person("王五", 13));
        list.add(new Person("赵六", 12));
        System.out.println("--------------- toMap 前");
        System.out.println(list);
        System.out.println("--------------- toMap 后");
        Map<String, Integer> map = list.stream().collect(Collectors.toMap(k -> k.getName(), v -> v.getAge()));
        System.out.println(map);
    }
}

